angular.module('app').config(($stateProvider) => {

    $stateProvider.state('app.lists', {
        url         : '/lists',
        label       : 'Lists',
        controller  : 'app.lists',
        controllerAs: '$ctrl',
        templateUrl : 'view/app/lists/lists.html'
    });
}).controller('app.lists', function ($scope, $ionicListDelegate, $timeout) {
    var ctrl = this;
    ctrl.items = [...new Array(10).keys()];
    ctrl.reorder = (item, from, to)=> {
        console.log(`item: ${item}`);
        console.log(`from: ${from}`);
        console.log(`to: ${to}`);

        ctrl.items.splice(from, 1);
        ctrl.items.splice(to, 0, item);
    };
    ctrl.deleteItem = (index)=> {
        if (confirm('确认删除? ')) {
            ctrl.items.splice(index, 1);
        }
    };
    ctrl.doPulling = ()=> {
        console.log('doPulling');
    };
    ctrl.doRefresh = ()=> {
        console.log('doRefresh');
        $timeout(()=> {
            $scope.$broadcast('scroll.refreshComplete');
        }, 1500);
    };
    ctrl.loadMoreData = ()=> {
        console.log('loadMoreData');
        $timeout(()=> {
            ctrl.items.push(ctrl.items.length);
            $scope.$broadcast('scroll.infiniteScrollComplete');
            if (ctrl.items.length === 12) {
                ctrl.noMoreData = true;
            }
        }, 1500);
    };

    /**
     * $ionicListDelegate
     */
    // $getByHandle: 通过 delegate-handle 获取一个实例
    // showReorder: 是否显示排序模式
    // showDelete: 是否显示删除模式
    // canSwipeItems: 是否允许滑动显示 option button
    // closeOptionButtons: 关闭显示出来了的 option button
    $timeout(()=> {
        $ionicListDelegate.$getByHandle('myList').showDelete(true);
    }, 1000);
});